package com.lw.reflection;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

/**
 * @author LW
 * @2020/9/22 15:13
 */
//获取类的信息
public class Test07 {

    public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException {
        Class c1 = Class.forName("com.lw.reflection.User");

        System.out.println(c1.getName());
        System.out.println(c1.getSimpleName());
        //获得类的属性
        Field[] fields = c1.getFields();//只能找到public参数
        fields = c1.getDeclaredFields();//找到全部

        for (int i = 0; i < fields.length; i++) {
            System.out.println(fields[i]);
        }
        //获得指定属性
        Field name = c1.getDeclaredField("name");
        System.out.println(name);

        //获得类的方法
        Method[] methods = c1.getDeclaredMethods();
        for (int i = 0; i < methods.length; i++) {
            System.out.println(methods[i]);
        }
    }
}
